-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: add CSRF trustedOrigins bypass list #14021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduces a new `allowedOrigins` array to the CSRF configuration, allowing trusted third-party origins to bypass CSRF origin checks for form submissions. Updates server logic to permit requests from these origins, extends type definitions and documentation, and adds comprehensive tests to verify correct behavior for allowed, blocked, and edge-case origins.
Renames the test to clarify it checks for undefined origin and removes the 'origin: null' header from the request. This ensures the test accurately reflects scenarios where the origin header is not set.
🦋 Changeset detectedLatest commit: 22f6b14 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Introduces an allowedOrigins array to the form configuration, enabling trusted third-party origins to bypass CSRF protection for cross-origin form submissions. This is useful for integrating with services like payment gateways or authentication providers.
This is great, thanks! renamed to Since this PR predates remote functions, they weren't considered for this, but I think it makes sense to continue to only allow same-origin remote function requests. So I made that change. I also think we could probably get rid of |
Adds
csrf.allowedOrigins
config to whitelist trusted domains that can submit forms to your app.Problem
Certain payment providers (and possibly auth services) redirect users back with form submissions that get blocked by CSRF protection. Previously you had to disable CSRF entirely or handle these outside SvelteKit. This is a fairly common Example thread
Solution
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits